/*   1:    */ package com.atomikos.beans;
/*   2:    */ 
/*   3:    */ import java.beans.BeanInfo;
/*   4:    */ import java.beans.IndexedPropertyDescriptor;
/*   5:    */ import java.beans.Introspector;
/*   6:    */ import java.beans.PropertyDescriptor;
/*   7:    */ 
/*   8:    */ public class BeanInspector
/*   9:    */ {
/*  10:    */   private Object bean_;
/*  11:    */   
/*  12:    */   public BeanInspector(Object bean)
/*  13:    */   {
/*  14: 54 */     this.bean_ = bean;
/*  15:    */   }
/*  16:    */   
/*  17:    */   public Property[] getProperties()
/*  18:    */     throws PropertyException
/*  19:    */   {
/*  20: 68 */     Property[] ret = null;
/*  21:    */     try
/*  22:    */     {
/*  23: 70 */       Class clazz = this.bean_.getClass();
/*  24: 71 */       BeanInfo info = Introspector.getBeanInfo(clazz);
/*  25: 72 */       if (info != null)
/*  26:    */       {
/*  27: 73 */         PropertyDescriptor[] props = info.getPropertyDescriptors();
/*  28: 74 */         if (props != null)
/*  29:    */         {
/*  30: 75 */           ret = new Property[props.length];
/*  31: 76 */           for (int i = 0; i < props.length; i++) {
/*  32: 77 */             if ((props[i] instanceof IndexedPropertyDescriptor))
/*  33:    */             {
/*  34: 78 */               IndexedPropertyDescriptor d = (IndexedPropertyDescriptor)props[i];
/*  35:    */               
/*  36: 80 */               ret[i] = new IndexedPropertyImp(this.bean_, d);
/*  37:    */             }
/*  38:    */             else
/*  39:    */             {
/*  40: 85 */               ret[i] = new PropertyImp(this.bean_, props[i]);
/*  41:    */             }
/*  42:    */           }
/*  43:    */         }
/*  44:    */       }
/*  45:    */     }
/*  46:    */     catch (Exception e)
/*  47:    */     {
/*  48: 95 */       throw new PropertyException("Error getting properties", e);
/*  49:    */     }
/*  50: 98 */     return ret;
/*  51:    */   }
/*  52:    */   
/*  53:    */   public Property getProperty(String name)
/*  54:    */     throws PropertyException
/*  55:    */   {
/*  56:110 */     Property ret = null;
/*  57:111 */     Property[] properties = getProperties();
/*  58:112 */     if (properties != null) {
/*  59:113 */       for (int i = 0; i < properties.length; i++) {
/*  60:114 */         if (properties[i].getName().equals(name)) {
/*  61:115 */           ret = properties[i];
/*  62:    */         }
/*  63:    */       }
/*  64:    */     }
/*  65:118 */     return ret;
/*  66:    */   }
/*  67:    */   
/*  68:    */   public Object getBean()
/*  69:    */   {
/*  70:130 */     return this.bean_;
/*  71:    */   }
/*  72:    */   
/*  73:    */   public void setPropertyValue(String name, String value)
/*  74:    */     throws ReadOnlyException, PropertyException
/*  75:    */   {
/*  76:146 */     Property p = getProperty(name);
/*  77:147 */     if (p == null) {
/*  78:148 */       throw new PropertyException("No such property: " + name);
/*  79:    */     }
/*  80:149 */     p.getEditor().setStringValue(value);
/*  81:150 */     p.setValue(p.getEditor().getEditedObject());
/*  82:    */   }
/*  83:    */   
/*  84:    */   public String getPropertyValue(String name)
/*  85:    */     throws PropertyException
/*  86:    */   {
/*  87:163 */     String ret = "";
/*  88:164 */     Property p = getProperty(name);
/*  89:165 */     Object val = p.getValue();
/*  90:166 */     if (val != null) {
/*  91:166 */       ret = val.toString();
/*  92:    */     }
/*  93:167 */     return ret;
/*  94:    */   }
/*  95:    */ }


/* Location:           C:\myfile\mysoft\apache-maven-3.5.0-bin\apache-maven-3.5.0\myrep\com\atomikos\atomikos-util\3.7.0\atomikos-util-3.7.0.jar
 * Qualified Name:     com.atomikos.beans.BeanInspector
 * JD-Core Version:    0.7.0.1
 */